/*
* Configuration of module: CanIf
*
* Created by:   qinminyuan
* Copyright:    (C)  
*
* Configured for (MCU):    MCU
*
* Module vendor:           ArcCore
* Generator version:       01.00
*/

/* ============================ [ INCLUDES  ] ====================================================== */
#include "CanIf.h"
#if defined(USE_CANTP)
#include "CanTp.h"
#include "CanTp_Cbk.h"
#endif
#if defined(USE_CANTPCLIENT)
#include "CanTpClient.h"
#endif
#if defined(USE_J1939TP)
#include "J1939Tp.h"
#include "J1939Tp_Cbk.h"
#endif
#if defined(USE_PDUR)
#include "PduR.h"
#endif
#if defined(USE_CANNM)
#include "CanNm_Cbk.h"
#endif
#if defined(USE_OSEKNM)
#include "OsekNm.h"
#endif
#if defined(USE_XCP)
#include "Xcp.h"
#include "XcpOnCan_Cbk.h"
#endif
/* ============================ [ MACROS    ] ====================================================== */
#define PDUR_ID2_STDOUT 0
#define PDUR_ID_STDIN 0
/* ============================ [ DECLARES  ] ====================================================== */
/* Imported structs from Can_PBcfg.c */
extern const Can_ControllerConfigType Can_ControllerCfgData[];
extern const Can_ConfigSetType Can_ConfigSetData;
extern void CanIf_User_BusoffNotification(uint8 Controller);
extern void CanIf_User_ErrorNotification(uint8 Controller,Can_Arc_ErrorType err);
extern void User_RxPdu0x3AE_RxIndication(uint8 channel, PduIdType pduId, const uint8 *sduPtr, uint8 dlc, Can_IdType canId);
extern void User_TxPdu0x3FA_TxConfirmation(PduIdType pduId);

/* ============================ [ DATAS     ] ====================================================== */
/* Contains the mapping from CanIf-specific Channels to Can Controllers */
#if 0
const CanControllerIdType CanIf_Arc_ChannelToControllerMap[CANIF_CHANNEL_CNT] = {
	CAN_CTRL_0                      ,/* Channel1                         */

};

const uint8 CanIf_Arc_ChannelDefaultConfIndex[CANIF_CHANNEL_CNT] = {
	Channel1_CONFIG_0,

};
#endif
/* Container that gets slamed into CanIf_InitController()
 * Inits ALL controllers
 * Multiplicity 1..* */
#if 0
const CanIf_ControllerConfigType CanIfControllerConfig[] = {

    {
        /* .WakeupSupport = CANIF_WAKEUP_SUPPORT_NO_WAKEUP, */
        .CanIfControllerIdRef = Channel1,
        /* .CanIfDriverNameRef = "FLEXCAN", */  /* Not used */
        .CanIfInitControllerRef = &Can_ControllerCfgData[INDEX_OF_CAN_CTRL_0],
    },

};
#endif


/* Function callbacks for higher layers */
const CanIf_DispatchConfigType CanIfDispatchConfig =
{
    .CanIfBusOffNotification = CanIf_User_BusoffNotification,
    .CanIfWakeUpNotification = NULL,        /* Not used */
    .CanIfWakeupValidNotification = NULL,   /* Not used */
    .CanIfErrorNotificaton = CanIf_User_ErrorNotification,
};
static const CanIf_HthConfigType CanIfHthConfigData_Channel1[]=
{

    {
        .CanIfHthType = CAN_ARC_HANDLE_TYPE_BASIC, /* TODO */
        .CanIfCanControllerIdRef = Channel1,
        .CanIfHthIdSymRef = Hoh0x7D2,
        .CanIf_Arc_EOL = FALSE
    },

    {
        .CanIfHthType = CAN_ARC_HANDLE_TYPE_BASIC, /* TODO */
        .CanIfCanControllerIdRef = Channel1,
        .CanIfHthIdSymRef = Hoh0x3FA,
        .CanIf_Arc_EOL = TRUE
    },
};

static const CanIf_HrhConfigType CanIfHrhConfigData_Channel1[]=
{

    {
        .CanIfHrhType = CAN_ARC_HANDLE_TYPE_BASIC, /* TODO: not used by CanIf now. */
        .CanIfSoftwareFilterHrh = TRUE, /* Must Be True */
        .CanIfCanControllerHrhIdRef = Channel1,
        .CanIfHrhIdSymRef = Hoh0x752,
        .CanIfHrhRangeConfig = NULL,
        .CanIf_Arc_EOL = FALSE
    },

    {
        .CanIfHrhType = CAN_ARC_HANDLE_TYPE_BASIC, /* TODO: not used by CanIf now. */
        .CanIfSoftwareFilterHrh = TRUE, /* Must Be True */
        .CanIfCanControllerHrhIdRef = Channel1,
        .CanIfHrhIdSymRef = Hoh0x7DF,
        .CanIfHrhRangeConfig = NULL,
        .CanIf_Arc_EOL = FALSE
    },

    {
        .CanIfHrhType = CAN_ARC_HANDLE_TYPE_BASIC, /* TODO: not used by CanIf now. */
        .CanIfSoftwareFilterHrh = TRUE, /* Must Be True */
        .CanIfCanControllerHrhIdRef = Channel1,
        .CanIfHrhIdSymRef = Hoh0x3AE,
        .CanIfHrhRangeConfig = NULL,
        .CanIf_Arc_EOL = TRUE
    },
};

const CanIf_InitHohConfigType CanIfHohConfigData[] =
{

    {
        //.CanConfigSet = &Can_ConfigSetData,
        .CanIfHrhConfig = CanIfHrhConfigData_Channel1,
        .CanIfHthConfig = CanIfHthConfigData_Channel1,
        .CanIf_Arc_EOL = TRUE
    },
};


#if defined(__WINDOWS__) || defined(__LINUX__)
#else
static const
#endif
CanIf_TxPduConfigType CanIfTxPduConfigData[] = 
{
    
    {//TxCANIF = 0
        .CanIfTxPduId = PDUR_ID2_Phys_DiagTx,
        .CanIfCanTxPduIdCanId = 0x7D2, 
        .CanIfCanTxPduIdDlc = 8,
        .CanIfCanTxPduType = CANIF_PDU_TYPE_STATIC,
    #if ( CANIF_READTXPDU_NOTIFY_STATUS_API == STD_ON )
        .CanIfReadTxPduNotifyStatus = TRUE,
    #endif
        .CanIfTxPduIdCanIdType = CANIF_CAN_ID_TYPE_11,
        .CanIfUserTxConfirmation = CanTp_TxConfirmation,
        .CanIfCanTxPduHthRef = &CanIfHthConfigData_Channel1[0],
        .PduIdRef = NULL
    },

    {//TxCANIF = 1
        .CanIfTxPduId = CANIF_ID_CMS_St,
        .CanIfCanTxPduIdCanId = 0x3FA, 
        .CanIfCanTxPduIdDlc = 8,
        .CanIfCanTxPduType = CANIF_PDU_TYPE_STATIC,
    #if ( CANIF_READTXPDU_NOTIFY_STATUS_API == STD_ON )
        .CanIfReadTxPduNotifyStatus = TRUE,
    #endif
        .CanIfTxPduIdCanIdType = CANIF_CAN_ID_TYPE_11,
        .CanIfUserTxConfirmation = User_TxPdu0x3FA_TxConfirmation,
        .CanIfCanTxPduHthRef = &CanIfHthConfigData_Channel1[1],
        .PduIdRef = NULL
    },

};


static const CanIf_RxPduConfigType CanIfRxPduConfigData[] = 
{
    
    {//RxCANIF = 0
        .CanIfCanRxPduId = CANIF_ID_Phys_DiagRx,
        .CanIfCanRxPduCanId = 0x752,
        .CanIfCanRxPduDlc = 8,
#if ( CANIF_CANPDUID_READDATA_API == STD_ON )
        .CanIfReadRxPduData = TRUE,
#endif
#if ( CANIF_READTXPDU_NOTIFY_STATUS_API == STD_ON )
        .CanIfReadRxPduNotifyStatus = TRUE,
#endif
        .CanIfRxPduIdCanIdType = CANIF_CAN_ID_TYPE_11,
        .CanIfRxUserType = CANIF_USER_TYPE_CAN_TP,
        .CanIfUserRxIndication = NULL,
        .CanIfCanRxPduHrhRef = &CanIfHrhConfigData_Channel1[0],
        .PduIdRef = NULL,
        .CanIfSoftwareFilterType = CANIF_SOFTFILTER_TYPE_MASK,
        .CanIfCanRxPduCanIdMask = 0x7FF
    },

    {//RxCANIF = 1
        .CanIfCanRxPduId = CANIF_ID_Func_DiagRx,
        .CanIfCanRxPduCanId = 0x7DF,
        .CanIfCanRxPduDlc = 8,
#if ( CANIF_CANPDUID_READDATA_API == STD_ON )
        .CanIfReadRxPduData = TRUE,
#endif
#if ( CANIF_READTXPDU_NOTIFY_STATUS_API == STD_ON )
        .CanIfReadRxPduNotifyStatus = TRUE,
#endif
        .CanIfRxPduIdCanIdType = CANIF_CAN_ID_TYPE_11,
        .CanIfRxUserType = CANIF_USER_TYPE_CAN_TP,
        .CanIfUserRxIndication = NULL,
        .CanIfCanRxPduHrhRef = &CanIfHrhConfigData_Channel1[1],
        .PduIdRef = NULL,
        .CanIfSoftwareFilterType = CANIF_SOFTFILTER_TYPE_MASK,
        .CanIfCanRxPduCanIdMask = 0x7FF
    },

    {//RxCANIF = 2
        .CanIfCanRxPduId = CANIF_ID_VIU_Route_Body,
        .CanIfCanRxPduCanId = 0x3AE,
        .CanIfCanRxPduDlc = 8,
#if ( CANIF_CANPDUID_READDATA_API == STD_ON )
        .CanIfReadRxPduData = TRUE,
#endif
#if ( CANIF_READTXPDU_NOTIFY_STATUS_API == STD_ON )
        .CanIfReadRxPduNotifyStatus = TRUE,
#endif
        .CanIfRxPduIdCanIdType = CANIF_CAN_ID_TYPE_11,
        .CanIfRxUserType = CANIF_USER_TYPE_CAN_SPECIAL,
        .CanIfUserRxIndication = User_RxPdu0x3AE_RxIndication,
        .CanIfCanRxPduHrhRef = &CanIfHrhConfigData_Channel1[2],
        .PduIdRef = NULL,
        .CanIfSoftwareFilterType = CANIF_SOFTFILTER_TYPE_MASK,
        .CanIfCanRxPduCanIdMask = 0x7FF
    },

};

/* This container contains the init parameters of the CAN
 * Multiplicity 1..* */
const CanIf_InitConfigType CanIfInitConfig =
{
    .CanIfConfigSet = 0, /* Not used */
    .CanIfNumberOfCanRxPduIds = sizeof(CanIfRxPduConfigData)/sizeof(CanIf_RxPduConfigType),
    .CanIfNumberOfCanTXPduIds = sizeof(CanIfTxPduConfigData)/sizeof(CanIf_TxPduConfigType),
    .CanIfNumberOfDynamicCanTXPduIds = 0, /* Not used */
    /* Containers */
    .CanIfHohConfigPtr = CanIfHohConfigData,
    .CanIfRxPduConfigPtr = CanIfRxPduConfigData,
    .CanIfTxPduConfigPtr = CanIfTxPduConfigData,
};
/* This container includes all necessary configuration sub-containers
 * according the CAN Interface configuration structure */
const CanIf_ConfigType CanIf_Config =
{
    //.ControllerConfig = CanIfControllerConfig,
    .DispatchConfig = &CanIfDispatchConfig,
    .InitConfig = &CanIfInitConfig,
    .TransceiverConfig = NULL, /* Not used */
    //.Arc_ChannelToControllerMap = CanIf_Arc_ChannelToControllerMap,
    //.Arc_ChannelDefaultConfIndex = CanIf_Arc_ChannelDefaultConfIndex,
};
/* ============================ [ LOCALS    ] ====================================================== */
/* ============================ [ FUNCTIONS ] ====================================================== */


